package com.sgcc.fj.pmos.mobileapp.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ToastUtils;
import com.sgcc.fj.pmos.arouter.app.AppArouterPath;
import com.sgcc.fj.pmos.common.base.BaseActivity;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvcNetCallback;
import com.sgcc.fj.pmos.common.widget.MyEditText;
import com.sgcc.ln.pmos.common.widget.TitleBar;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.mobileapp.bean.MouldEditionBean;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

/**
 * 实名认证
 */
@Route(path = AppArouterPath.APP_REALNAMEAUTH)
public class RealNameAuthActivity extends BaseActivity {

    private TitleBar titleBar;
    private TextView tvAccount;
    private MyEditText etName;
    private MyEditText etIdCard;
    private TextView btnNext;

    @Autowired
    public String Account;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_realnameauth;
    }

    @Override
    protected void initViews() {
        super.initViews();
        findViewByIds();
    }

    private void findViewByIds() {
        titleBar = (TitleBar) findViewById(R.id.title_bar);
        tvAccount = (TextView) findViewById(R.id.tv_account);
        etName = (MyEditText) findViewById(R.id.et_name);
        etIdCard = (MyEditText) findViewById(R.id.et_idCard);
        btnNext = (TextView) findViewById(R.id.btn_next);

        titleBar.setTitle("实名认证");
        titleBar.setRightIcon(R.mipmap.go_main, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goMainActivity();
            }
        });

        tvAccount.setText(Account);

        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = etName.getText().toString().trim();
                if (TextUtils.isEmpty(name)) {
                    ToastUtils.showShort("请输入姓名");
                    return;
                }
                String etIdCard = etName.getText().toString().trim();
                if (TextUtils.isEmpty(etIdCard)) {
                    ToastUtils.showShort("请输入身份证号码");
                    return;
                }
                queryForBound(name, etIdCard);
            }
        });
    }

    /**
     * 账号实名认证
     */
    public void queryForBound(String auth_id, String auth_people) {
        Map<String, Object> params = new HashMap<>();
        params.put("auth_id", auth_id);
        params.put("auth_people", auth_people);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.QUERYFORBOUND, new MvcNetCallback<MouldEditionBean>(true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                ARouter.getInstance()
                        .build(AppArouterPath.APP_ASSOCIATEDENTERPRISEINFO)
                        .navigation();
            }

            @Override
            public void onResponse(MouldEditionBean response, int id) {
                super.onResponse(response, id);
                ARouter.getInstance()
                        .build(AppArouterPath.APP_ASSOCIATEDENTERPRISEINFO)
                        .navigation();
//                if (response != null) {
//                    if (response.getStatus() == 0 && "Success".equals(response.getMessage())) {
//                        ARouter.getInstance()
//                                .build(AppArouterPath.APP_ASSOCIATEDENTERPRISEINFO)
//                                .navigation();
//                    }
//                }
            }
        });
    }
}
